classdef model_EW2D
% DESCRIPTION
%   EW equation in 2D in a domain [-pi,pi)x[-pi,pi)
%   Solve the EW equation using model decomposition method
    properties
        c2 = [];
        sigma2 = [];
        time = [];
        mode = 1;
        z1 = [];
        z2 = [];
        z3 = [];
        z4 = [];
    end
    properties(Dependent = true)
        r2 = [];
        m2 = [];
    end
    
    methods
        function obj = model_EW2D(time,varargin)
            obj.time = time;
            if nargin == 3
                obj.c2 = varargin{1};
                obj.sigma2 = varargin{2};
            end
        end
        
        function obj = Identifiy(obj,r2)
            
        end
        
        function obj = solve(obj)
            % Solve the mean value of EW equation based on model
            % decomposition method
            assert(~isempty(c2) && ~isempty(sigma2) && ~isempty(time));
        end
        
        function r2 = get.r2(obj)
            r2 = zeros(size(obj.time));
            for i = 1:length(obj.time)
                r2_temp = 0.0;
                for m = 0:obj.mode
                    for n = 0:obj.mode
                        if(m~=0||n~=0)
                            lambda = -4.0*obj.c2*(m^2+n^2);
                            temp1 = exp(2*lambda*time(i));
                            if(m==0||n==0)
                                r2_temp = r2_temp+2*obj.sigma2*(temp1-1)/(2*lambda);
                            else
                                r2_temp = r2_temp+4*obj.sigma2*(temp1-1)/(2*lambda);
                            end
                        end
                    end
                end
                r2(i) = r2_temp/(pi*pi);
            end
        end
        
    end
    
end